import java.util.ArrayList;
import java.util.List;

class Receiver
{
	public void showA() { System.out.println("Receiver.showA()"); }
	public void showB() { System.out.println("Receiver.showB()"); }
}

public abstract class Command
{
    public static void main(String[] args) {
        Receiver r = new Receiver();
        Command ca = new CommandA(r);
        Command cb = new CommandB(r);
        Invoker ivk = new Invoker();
        ivk.add(ca);
        ivk.add(cb);
        ivk.add(ca);
        ivk.add(cb);
        ivk.remove(ca);
        ivk.invoke();    
    }

	public Receiver Receiver;
    public abstract void show();
    public Command(Receiver receiver){
        this.Receiver = receiver;
    }
}
class CommandA extends Command
{
    public CommandA(Receiver receiver){
        super(receiver);
    }
    @Override
	public void show()
	{
		this.Receiver.showA();
	}
}
class CommandB extends Command
{
    public CommandB(Receiver receiver){
        super(receiver);
    }
    @Override
	public void show()
	{
		this.Receiver.showB();
	}
}
class Invoker
{    
	List<Command> commands = new ArrayList<Command>();
	public void add(Command c) { this.commands.add(c); }
	public void remove(Command c) { this.commands.remove(c); }
	public void invoke()
	{
		for (Command command : commands)
		{
			command.show();
		}
	}
}